package com.sc.core.util.translator;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
public class TranslatorFactory {

    private final Map<String, ITranslatorProvider> translatorProviders;

    public TranslatorFactory(Map<String, ITranslatorProvider> translatorProviders) {
        this.translatorProviders = translatorProviders;
    }

    public ITranslatorProvider getTranslator(String name){
        return Optional.ofNullable(translatorProviders.get(name))
                .orElseThrow(() -> new RuntimeException("翻译器不存在：" + name));
    }
}
